package com.gitee.sop.layui.adminserver.module.background.admin.rest;

import com.gitee.sop.layui.adminserver.module.background.admin.service.SysUserFunctionRoleRelationService;
import com.gitee.sop.layui.adminserver.module.base.bo.ValidGroup;
import com.gitee.sop.layui.adminserver.module.base.constants.Result;
import com.gitee.sop.layui.adminserver.module.base.error.ServiceInterruptionException;
import com.gitee.sop.layui.adminserver.module.base.util.AssertUtil;
import org.springframework.context.annotation.Lazy;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.stream.Collectors;

/**
 * com.zch.admin.base.entity.SysAdminFnroleUserRelation模型http接口处理
 *
 * @author: admin
 * @date: 2019-11-28
 * @version: 1.0.0
 */
@Validated(value = {ValidGroup.All.class})
@RestController
@RequestMapping(value = "/admin/userFunctionRoleRelation", produces = {MediaType.APPLICATION_JSON_UTF8_VALUE})
public class SysUserFunctionRoleRelationRestController {

    @Lazy
    @Resource
    private SysUserFunctionRoleRelationService baseService;

    @RequestMapping(value = {"/setAuthority/{userUuid}"})
    public Result setAuthority(@PathVariable(value = "userUuid") String userUuid, @RequestParam(value = "fnRoleIds") Integer[] fnRoleIds) {
        AssertUtil.isTrue(fnRoleIds.length < 100, ServiceInterruptionException.fail(400, "参数错误"));
        baseService.setAuthority(userUuid, Arrays.stream(fnRoleIds).collect(Collectors.toList()));
        return Result.success();
    }
}
